/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* E.P. Scene Graph
* Developed by:
*       - Eduardo Ribeiro (eribeiro @ tecgraf . puc-rio . br)
*       - Peter Dam (peter @ tecgraf . puc-rio . br)
* File: Texture.h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _EPSG_TEXTURE_
#define _EPSG_TEXTURE_

#include "EPSG/Prototypes.h"
#include "EPSG/Appearance.h"
#include <string>

namespace EPSG
{
	class Texture : public Appearance
	{
	public:
		enum TextureType
		{
			EPSG_TEXTURE_1D,
			EPSG_TEXTURE_2D
			//EPSG_TEXTURE_3D
		};

		enum TextureFunc
		{
			EPSG_MODULATE,
			EPSG_DECAL,
			EPSG_BLEND,
			EPSG_REPLACE
		};

		enum TextureFilter
		{
			EPSG_NEAREST,
			EPSG_LINEAR,
			EPSG_NEAREST_MIPMAP_NEAREST,
			EPSG_LINEAR_MIPMAP_NEAREST,
			EPSG_NEAREST_MIPMAP_LINEAR,
			EPSG_LINEAR_MIPMAP_LINEAR
		};

		enum TextureRepeat
		{
			EPSG_REPEAT,
			EPSG_CLAMP
			//EPSG_CLAMP_TO_BORDER,
			//EPSG_CLAMP_TO_EDGE
		};

		enum TextureProjective
		{
			EPSG_NOT_PROJECTIVE,
			EPSG_PROJECTION_OBJECT,
			EPSG_PROJECTION_EYE
		};

		/* [CONSTRUCTOR] */ Texture();
		/* [CONSTRUCTOR] */ Texture( const char* path );
		/* [DESTRUCTOR]  */	~Texture();

		virtual bool		load();
		virtual void		unload();

		bool				loadFile( std::string path,
									  TextureType type = EPSG_TEXTURE_2D,
									  TextureFunc func = EPSG_MODULATE, 
									  TextureFilter minFilter = EPSG_LINEAR_MIPMAP_LINEAR,
									  TextureFilter magFilter = EPSG_LINEAR, 
									  TextureRepeat repMode = EPSG_REPEAT );

		void				setProjective( TextureProjective projectiveType );

		void				setPlaneS( float a, float b, float c, float d );
		void				setPlaneT( float a, float b, float c, float d );

	private:
		unsigned int		epsgToGL_TextureType( TextureType& type );
		float				epsgToGL_TextureFunc( TextureFunc& func );
		float				epsgToGL_TextureFilter( TextureFilter& filter );
		float				epsgToGL_TextureRepeat( TextureRepeat& repeat );

		std::string			_loadedImagePath;
		GLubyte*			_imageBuffer;
		unsigned int		_texID;
		unsigned int		_texType;
		float				_texFunc;
		float				_minFilter;
		float				_magFilter;
		float				_repMode;

		float _planeS[4];
		float _planeT[4];

		TextureProjective	_projectiveType;
	};
}

#endif //_EPSG_TEXTURE_